package com.jinsi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.pojo.ScUser;
import com.jinsi.pojo.ScUserLoginLog;
import com.jinsi.service.ScHomePageServer;
import com.jinsi.utils.MapReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Date : 2022/7/7 19:34
 * 小南不难
 **/
@RequestMapping("/homepage")
@RestController
public class HomePageConteroller {

    @Autowired
    private ScHomePageServer scHomePageServer;

    @GetMapping("/getTodayPriceAndCount")
    public Map<String,Object> getTodayPriceAndCount(){
        return scHomePageServer.getTodayPriceAndCount();
    }

    @GetMapping("/getJoinAndPre")
    public Map<String,Object>  getJoinAndPre() {
        return scHomePageServer.getJoinAndPre();
    }

    //获取近一月的资金流水走势
    @GetMapping("/getOneMouthPrice")
    public Map<String,Object> getOneMouthPrice(){
        return scHomePageServer.getOneMouthPrice();
    }

    //获取支付方式数据结果
    @GetMapping("/getPriceWay")
    public Map<String,Object> getPriceWay(){
        return scHomePageServer.getPriceWay();
    }

    //查询登录日志
    @GetMapping("/getLoginLog")
    public Map<String,Object> getLoginLog(int page,int limit){
        Map<String,Object> ret =  scHomePageServer.getLoginLog();
        PageHelper.startPage(page,limit);
        if(ret.get("state").equals("200")){
            //登陆成功
            List<ScUserLoginLog> scUserLoginLog = (List<ScUserLoginLog>) ret.get("data");//获取数据
            PageInfo<ScUserLoginLog> pageInfo = new PageInfo(scUserLoginLog);
            return MapReturn.getTable("0","请求成功",(int)pageInfo.getTotal(),pageInfo.getList());
        }else {
            return MapReturn.getTable("500","数据获取失败",0,null);
        }

    }

    //日志删除
    @GetMapping("/delLoginLog")
    public Map<String,Object> delLoginLog(int id){
        return scHomePageServer.delLoginLog(id);
    }

    //用户信息修改
    @PostMapping("/uptUserInfo")
    public Map<String,Object> uptUserInfo(ScUser scUser){
        return scHomePageServer.uptUserInfo(scUser);
    }
    //密码修改
    @PostMapping("/uptUserPwd")
    public Map<String,Object> uptUserPwd(String oldpwd,String newpwda,String newpwdb,int userId){
        System.out.println(oldpwd+" " + newpwda + " "+userId);
        return scHomePageServer.uptUserpwd(oldpwd,newpwda,userId);
    }

}
